home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus 2002 #3
/
Amiga Plus CD - 2002 - No. 03.iso
/
AmiSoft
/
Util
/
Misc
/
Chkindex.lha
/
ChkIndex
/
ChkIndex.s
< prev
next >
Wrap
Text File
|
2003-01-22
|
44KB
|
1,564 lines
*****************************************************************************
* *
* PROGRAM: ChkIndex *
* VERSION: 1.9 *
* SOURCE CODE: 32 *
* DATE: 22.12.2002 - 22.01.2003 *
* LANGUAGE: Assembler (DevPac V3.14) *
* SYSTEM: A1200 KS 40.68 WB 40.42 2MB chip 64MB fast 68030/50mhz *
* *
* AUTHOR: Joerg Riemer 14167 Berlin/SchottmuellerStr.107/Germany *
* EMAIL: joerg_riemer@freenet.de / mission@cs.tu-berlin.de *
* *
* COMMENT: search the aminet index_file for identical entries *
* *
* TEMPLATE: INDEX/A,OUTPUT/A,WS=WRITESORTED/K,SKIP/N *
* *
* INDEX/A path/name of indexfile *
* OUTPUT/A just the outputfile for identical lines *
* WRITESORTED/K save indexfile sorted by filename *
* SKIP/N skip # of lines (index header = 8 lines) *
* *
* OPTION: To make ChkIndex as short as possible, set BSS_Section *
* to NULL and use StripHunk to generate a Code_BSS-segment. *
* spares some bytes! but for anybody don't know what this *
* means: "leave it as it is" *
* *
* StripHunk is available at AmiNet dev/misc/... *
* *
* for suggestions, hints/tips, and/or questions, *
* send an email! (see above for address) *
* *
*****************************************************************************
* opt d+
* opt o+
BSS_Section set 1
*****************************************************************************
output ram:ChkIndex
*****************************************************************************
*
* small statistic (checked while debugging)
*
* aminet indexfile size: 5.277.715 lines: 71.861 date: 16.3.2003
*
* GetIFile = 2.017744 sec. (open file; allocmem; read file)
* CreateEList = 2.613314 sec. (allocmem; create list for all lines)
* SortEList = 6.436765 sec. (sort list [quicksort])
* GetMEntries = 3.829775 sec. (search for multiple entries; write lines)
* -----------------------------
* 14.897598 sec.
* -----------------------------
* WriteSFile = 14.691603 sec. (write sorted file [line by line])
* -----------------------------
* 29.589201 sec.
*
************************************************ exec definitions ***********
_LVOOpenLibrary equ -552
_LVOCloseLibrary equ -414
_LVOAllocMem equ -198
_LVOFreeMem equ -210
_LVOCacheClearU equ -636
************************************************ dos definitions ************
_LVOOutput equ -060
_LVOIoErr equ -132
_LVOFPutC equ -312
_LVOFPuts equ -342
_LVOSetIoErr equ -462
_LVOPrintFault equ -474
_LVOReadArgs equ -798
_LVOFreeArgs equ -858
_LVOMatchFirst equ -822
_LVOMatchNext equ -828
_LVOMatchEnd equ -834
_LVOOpen equ -030
_LVOClose equ -036
_LVORead equ -042
_LVOWrite equ -048
_LVODeleteFile equ -072
_LVORename equ -078
_LVOLock equ -084
_LVOUnLock equ -090
_LVOCurrentDir equ -126
_LVOSetComment equ -180
_LVOSetProtection equ -186
_LVOFlush equ -360
_LVOExamineFH equ -390
_LVOCheckSignal equ -792
_LVOFilePart equ -870
_LVOPutStr equ -948
_LVOVPrintf equ -954
MODE_OLDFILE equ 1005
MODE_NEWFILE equ 1006
ACCESS_READ equ -002
fib_DirEntryType equ $004
fib_Protection equ $074
fib_Size equ $07C
fib_Comment equ $090
fib_SIZEOF equ $104
FIBB_ARCHIVE equ $004
SIGBREAKB_CTRL_C equ $00C
SIGBREAKB_CTRL_D equ $00D
SIGBREAKB_CTRL_E equ $00E
SIGBREAKB_CTRL_F equ $00F
************************************************ bss datas ******************
FIBlock rs.b fib_SIZEOF ;buffer for fileinfoblock
DOSBase rs.l 1 ;ptr. base of library
ArgArray rs.l 0 ;argarray
IndexFile rs.l 1 ;ptr. path/name indexfile
OutputFile rs.l 1 ;ptr. path/name outputfile
SortedFile rs.l 1 ;ptr. path/name sorted ifile
SkipHead rs.l 1 ;# of lines to skip
RDArgs rs.l 1 ;returned by readargs
IHandle rs.l 1 ;handle indexfile
OHandle rs.l 1 ;handle outputfile
SHandle rs.l 1 ;handle sorted indexfile
MemoryA rs.l 1 ;membase indexfile
MemoryB rs.l 1 ;membase indexfile w/o head
RCode1 rs.l 1 ;errorcode > rc
RCode2 rs.l 1 ;errorcode > result2
Count rs.l 1 ;# of bytes written out/file
SCount rs.l 1 ;# of bytes written sort/file
EList rs.l 1 ;membase entrylist
ELSize rs.l 1 ;size of entrylist
Lines rs.l 1 ;# of lines (ifile w/o head)
BSS_Size rs.b 0 ;bss_size over all
*****************************************************************************
Start movem.l D1-D7/A0-A6,-(SP) ;save registers
if BSS_Section ;check assembler condition
movea.l Start-4(pc),A5 ;get bss_section
addq.l #1,A5 ;skip pointer (next segment)
adda.l A5,A5 ;convert bpcl_pointer
adda.l A5,A5 ;to real_address
elseif ;otherwise
lea DataBase(pc),A5 ;set data area
endc ;end condition
************************************************ open libraries *************
moveq #20,D0 ;failat level
move.l D0,RCode1(A5) ;preset error (no library)
movea.l 4.w,A6 ;set EXEC to call a function
moveq #37,D0 ;required library version
lea DOSName(pc),A1 ;set library name
jsr _LVOOpenLibrary(A6) ;use EXEC to (openlibrary)
move.l D0,DOSBase(A5) ;save base
beq.b CloseLibs ;branch if not open
*****************************************************************************
bsr.b Main
************************************************ close libraries ************
CloseLibs movea.l 4.w,A6 ;set EXEC to call a function
CloseDOS move.l DOSBase(A5),D1 ;get base_ptr
beq.b ExitDOS ;branch when not open
movea.l D1,A1 ;set base_ptr
jsr _LVOCloseLibrary(A6) ;use EXEC to (closelibrary)
ExitDOS move.l RCode1(A5),D0 ;set returncode
movem.l (SP)+,D1-D7/A0-A6 ;restore registers
rts ;go back (shell)
*****************************************************************************
DOSName dc.b "dos.library",0
*****************************************************************************
version dc.b "$VER: ChkIndex 1.9 32 (22.01.03) by joerg riemer jan'03",0
*****************************************************************************
cnop 0,4
*****************************************************************************
Main clr.l RCode1(A5) ;clear returncode
bsr ReadArgs ;read user_arguments
bsr CheckArgs ;check for legal arguments
bsr OpenOFile ;open outputfile
bsr OpenSFile ;open sorted indexfile (new)
bsr GetIFile ;read indexfile
bsr SkipHeader ;skip headlines
bsr.b ChkBreak ;check for user break
bsr.b CreateEList ;create entrylist
bsr.b ChkBreak ;check for user break
bsr SortEList ;sort entrylist
bsr.b ChkBreak ;check for user break
bsr WriteSFile ;write sorted indexfile
bsr GetMEntries ;search for multiple entries
Quit bsr FreeEList ;free memory (indexlist)
bsr FreeMem ;free memory (indexfile)
bsr CloseIFile ;close indexfile
bsr CloseSFile ;close sorted indexfile
bsr CloseOFile ;close outputfile
bsr FreeArgs ;free memory (readargs)
rts ;go back
*****************************************************************************
cnop 0,4
*****************************************************************************
ChkBreak moveq #00,D1 ;prepare signal mask
bset #12,D1 ;set break bit (ctrl_c)
movea.l DOSBase(A5),A6 ;set DOS to call a function
jsr _LVOCheckSignal(A6) ;use DOS to (checksignal)
btst #12,D0 ;test break bit (ctrl_c)
bne Error3 ;if set, branch (set ioerr)
rts ;go back
*****************************************************************************
cnop 0,4
*****************************************************************************
CreateEList movea.l MemoryB(A5),A0 ;base of indexfile w/o head
moveq #0,D0 ;prepare register
moveq #10,D7 ;set linefeed
;-----------------------------------------------
.calclines cmp.b (A0)+,D7 ;search for linefeed
bne.b .calclines ;do until
addq.l #1,D0 ;inc. number of lines
tst.b (A0) ;check for eof
bne.b .calclines ;do until
;-----------------------------------------------
move.l D0,Lines(A5) ;save # of lines
lsl.l #3,D0 ;need 8 bytes for each line!
addq.l #8,D0 ;list terminator
move.l D0,ELSize(A5) ;save size
moveq #0,D1 ;no memory options
movea.l 4.w,A6 ;set EXEC to call a function
jsr _LVOAllocMem(A6) ;use EXEC to (allocmem)
move.l D0,EList(A5) ;save memorybase
beq Error2 ;branch if fail (close file)
;-----------------------------------------------
movea.l MemoryB(A5),A0 ;get indexfile
movea.l EList(A5),A1 ;get entrylist
.addlist moveq.l #0,D0 ;reset register
move.l A0,(A1)+ ;save base of line
.getlength addq.l #1,D0 ;inc. length of line
cmp.b (A0)+,D7 ;search for linefeed
bne.b .getlength ;do until
move.l D0,(A1)+ ;save length of line
tst.b (A0) ;check for eof
bne.b .addlist ;do until
moveq #0,D0 ;get terminator
move.l D0,(A1)+ ;set list_terminator
move.l D0,(A1) ;set list_terminator
rts ;go back
******************************************************************************
cnop 0,4
*********************************************** sort indexlist *************
SortEList movea.l EList(A5),A0 ;get entrylist
move.l Lines(A5),D1 ;get # of lines
beq QuitSort ;branch if zero
moveq #0,D0 ;init. left
subq.l #1,D1 ;init. right
moveq #32,D3 ;compare lowercase!
quicksort: movem.l D4-7,-(SP)
************************************************
* le = lo; ri = hi *****************************
move.l D0,D4 ;left
move.l D1,D5 ;right
move.l D0,D6 ;low
move.l D1,D7 ;high
************************************************
* p = (hi+lo)/2 ********************************
move.l D1,D2 ;get high
add.l D0,D2 ;(hi+lo)
lsr.l #1,D2 ;(hi+lo)/2
lsl.l #3,D2 ;offset for 2 lwords
move.l 0(A0,D2.l),A3 ;get pivotelement
move.l 4(A0,D2.l),A4 ;get length of pivotelement
subq.l #1,A4 ;dbra!!
bra.b le_loop_1
************************************************
* while (f[le] < p) ; le++ *********************
le_loop_2 addq.l #1,D4 ;le++
le_loop_1 move.l D4,D0 ;set left_index
lsl.l #3,D0 ;prepare offset
movea.l 0(A0,D0.l),A1 ;get entry to compare
movea.l A3,A2 ;set pivotelement
move.l A4,D2 ;set length of pivotelement
le_compare move.b (A1)+,D0 ;compare entries
move.b (A2)+,D1 ;char. by char.
or.b D3,D0 ;force lowercase
or.b D3,D1 ;for both
cmp.b D1,D0
dbne d2,le_compare ;do until eol
bhi.b ri_loop_1 ;branch if entry > pivot
tst.w d2 ;entry = pivot ?
bpl.b le_loop_2 ;inc. left_index if not
************************************************
bra.b ri_loop_1
************************************************
* while ( p < f[ri]); ri-- *********************
ri_loop_2 subq.l #1,D5 ;ri--
ri_loop_1 move.l D5,D0 ;set right_index
lsl.l #3,D0 ;prepare offset
movea.l 0(A0,D0.l),A1 ;get entry to compare
movea.l A3,A2 ;set pivotelement
move.l A4,D2 ;set length of pivotelement
ri_compare move.b (A1)+,D0 ;compare entries
move.b (A2)+,D1 ;char. by char.
or.b D3,D0 ;force lowercase
or.b D3,D1 ;for both
cmp.b D1,D0
dbne d2,ri_compare ;do until eol
bcs.b skip1 ;branch if entry < pivot
tst.w d2 ;entry = pivot ?
bpl.b ri_loop_2 ;dec. right_index if not
************************************************
* if (le <= ri); swap (f,le,ri); le++; ri-- ****
skip1 cmp.l D5,D4 ;left<=right ?
bgt.b skip2 ;
beq.b skip3 ;
move.l D4,D0 ;left
lsl.l #3,D0
movea.l A0,A1
adda.l D0,A1
move.l D5,D1 ;right
lsl.l #3,D1
movea.l A0,A2
adda.l D1,A2
move.l (A1),D2 ;24 swap entry pointers
move.l (A2),(A1)+ ;40
move.l D2,(A2)+ ;24
move.l (A1),D2 ;24 swap entry_length, too
move.l (A2),(A1) ;40
move.l D2,(A2) ;24 176
skip3 addq.l #1,D4 ;le++
subq.l #1,D5 ;ri--
************************************************
* if le <= ri do again *************************
cmp.l D5,D4 ;right,left
ble.b le_loop_1
************************************************
* if (lo < ri) quicksort (f,lo,ri) *************
skip2 cmp.l D5,D6 ;right,low
bge.b goon_1
move.l D6,D0 ;
move.l D5,D1
bsr quicksort
************************************************
* if (le < hi) quicksort (f,le,hi) *************
goon_1: cmp.l D4,D7 ;left,high
ble.b goon_2
move.l D4,D0 ;left
move.l D7,D1 ;high
bsr quicksort
************************************************
goon_2: movem.l (SP)+,D4-7
QuitSort rts
*****************************************************************************
cnop 0,4
*****************************************************************************
WriteSFile move.l SHandle(A5),D6 ;get filehandle
beq.b .quit ;quit if not set
move.l Lines(A5),D7 ;get # of lines
movea.l EList(A5),A2 ;get entrylist
movea.l DOSBase(A5),A6 ;set DOS to call a function
.WriteLine move.l D6,D1 ;set file
move.l (A2)+,D2 ;set buffer
move.l (A2)+,D3 ;set size
jsr _LVOWrite(A6) ;write file (line by line)
add.l D0,SCount(A5) ;inc. byte count
subq.l #1,D7 ;dec. line count
bne.b .WriteLine ;do for all lines
.quit rts ;go back
*****************************************************************************
cnop 0,4
*****************************************************************************
GetMEntries moveq #32,D5 ;compare lowercase!
moveq #0,D6 ;skip_over flag
bset #31,D6 ;for compared entries
move.l OHandle(A5),D7 ;file_handle
movea.l DOSBase(A5),A6 ;DOSbase
bsr Search_0 ;filename,path
bsr Search_1 ;filename,size,age,description
bsr Search_3 ;filename,size,age
bsr Search_2 ;filename,size,description
bsr Search_5 ;filename,size
bsr Search_4 ;filename,age,description
bsr Search_6 ;filename,age
bsr.b Search_7 ;filename,description
* bsr Search_8 ;filename
*****************************************************************************
* search FILENAME
Search_8 move.l D7,D1 ;set file
lea String8(pc),A0 ;get buffer
move.l A0,D2 ;set buffer
move.l #S8Size,D3 ;set length
jsr _LVOWrite(A6) ;use DOS to (write) bytes
movea.l EList(A5),A2 ;entrylist
subq.l #8,A2 ;simple avoids bra!
.IncListA addq.l #8,A2 ;inc. list_a
tst.l (A2) ;check for eol
beq QuitSearch ;branch if so
tst.l 4(A2) ;test for skip_over
bmi.b .IncListA ;branch if so
moveq #0,D4 ;clr flag (print sourceline)
movea.l A2,A3 ;set list_b
.IncListB addq.l #8,A3 ;inc. list_b
move.l (A3),D1 ;check for eol
beq QuitSearch ;branch if so
tst.l 4(A3) ;test for skip_over
bmi.b .IncListB ;branch if so
;-----------------------------------------------
moveq #18,D2 ;loopcounter
movea.l (A2),A0 ;get filename_field entry (a)
movea.l D1,A1 ;get filename_field entry (b)
.Compare_1 move.b (A0)+,D0 ;compare filenames
move.b (A1)+,D1 ;char. by char.
or.b D5,D0 ;force lowercase
or.b D5,D1 ;for both
cmp.b D0,D1 ;compare chars.
dbne D2,.Compare_1 ;do loop as long as equal
;and counter is positive
tst.w D2 ;found same filenames ?
bpl.b .IncListA ;branch if not
pea .IncListB(pc) ;set return_address
bra WriteEntries ;save entries
*****************************************************************************
cnop 0,4
*****************************************************************************
* search FILENAME, DESCRIPTION
Search_7 move.l D7,D1 ;set file
lea String7(pc),A0 ;get buffer
move.l A0,D2 ;set buffer
move.l #S7Size,D3 ;set length
jsr _LVOWrite(A6) ;use DOS to (write) bytes
movea.l EList(A5),A2 ;entrylist
subq.l #8,A2 ;simple avoids bra!
.IncListA addq.l #8,A2 ;inc. list_a
tst.l (A2) ;check for eol
beq QuitSearch ;branch if so
tst.l 4(A2) ;test for skip_over
bmi.b .IncListA ;branch if so
moveq #0,D4 ;clr flag (print sourceline)
movea.l A2,A3 ;set list_b
.IncListB addq.l #8,A3 ;inc. list_b
move.l (A3),D1 ;check for eol
beq QuitSearch ;branch if so
tst.l 4(A3) ;test for skip_over
bmi.b .IncListB ;branch if so
;-----------------------------------------------
moveq #18,D2 ;loopcounter
movea.l (A2),A0 ;get filename_field entry (a)
movea.l D1,A1 ;get filename_field entry (b)
.Compare_1 move.b (A0)+,D0 ;compare filenames
move.b (A1)+,D1 ;char. by char.
or.b D5,D0 ;force lowercase
or.b D5,D1 ;for both
cmp.b D0,D1 ;compare chars.
dbne D2,.Compare_1 ;do loop as long as equal
;and counter is positive
tst.w D2 ;found same filenames ?
bpl.b .IncListA ;branch if not
;-----------------------------------------------
move.l 4(A2),D2 ;loopcounter
sub.l #39,D2
lea 19(A0),A0 ;get description_field (a)
lea 19(A1),A1 ;get description_field (b)
.Compare_4 move.b (A0)+,D0 ;compare file_descriptions
move.b (A1)+,D1 ;char. by char.
or.b D5,D0 ;force lowercase
or.b D5,D1 ;for both
cmp.b D0,D1 ;compare chars.
dbne D2,.Compare_4 ;do loop as long as equal
;and counter is positive
tst.w D2 ;found same description ?
bpl.b .IncListB ;branch if not
pea .IncListB(pc) ;set return_address
bra WriteEntries ;save entries
*****************************************************************************
cnop 0,4
*****************************************************************************
* search FILENAME, AGE
Search_6 move.l D7,D1 ;set file
lea String6(pc),A0 ;get buffer
move.l A0,D2 ;set buffer
move.l #S6Size,D3 ;set length
jsr _LVOWrite(A6) ;use DOS to (write) bytes
movea.l EList(A5),A2 ;entrylist
subq.l #8,A2 ;simple avoids bra!
.IncListA addq.l #8,A2 ;inc. list_a
tst.l (A2) ;check for eol
beq QuitSearch ;branch if so
tst.l 4(A2) ;test for skip_over
bmi.b .IncListA ;branch if so
moveq #0,D4 ;clr flag (print sourceline)
movea.l A2,A3 ;set list_b
.IncListB addq.l #8,A3 ;inc. list_b
move.l (A3),D1 ;check for eol
beq QuitSearch ;branch if so
tst.l 4(A3) ;test for skip_over
bmi.b .IncListB ;branch if so
;-----------------------------------------------
moveq #18,D2 ;loopcounter
movea.l (A2),A0 ;get filename_field entry (a)
movea.l D1,A1 ;get filename_field entry (b)
.Compare_1 move.b (A0)+,D0 ;compare filenames
move.b (A1)+,D1 ;char. by char.
or.b D5,D0 ;force lowercase
or.b D5,D1 ;for both
cmp.b D0,D1 ;compare chars.
dbne D2,.Compare_1 ;do loop as long as equal
;and counter is positive
tst.w D2 ;found same filenames ?
bpl.b .IncListA ;branch if not
;-----------------------------------------------
moveq #2,D2 ;loopcounter
lea 16(A0),A0 ;get age_field entry (a)
lea 16(A1),A1 ;get age_field entry (b)
.Compare_3 move.b (A0)+,D0 ;compare filesizes
move.b (A1)+,D1 ;char. by char.
or.b D5,D0 ;force lowercase
or.b D5,D1 ;for both
cmp.b D0,D1 ;compare chars.
dbne D2,.Compare_3 ;do loop as long as equal
;and counter is positive
tst.w D2 ;found equal filesize ?
bpl.b .IncListB ;branch if not
pea .IncListB(pc) ;set return_address
bra WriteEntries ;save entries
*****************************************************************************
cnop 0,4
*****************************************************************************
* search FILENAME, SIZE
Search_5 move.l D7,D1 ;set file
lea String5(pc),A0 ;get buffer
move.l A0,D2 ;set buffer
move.l #S5Size,D3 ;set length
jsr _LVOWrite(A6) ;use DOS to (write) bytes
movea.l EList(A5),A2 ;entrylist
subq.l #8,A2 ;simple avoids bra!
.IncListA addq.l #8,A2 ;inc. list_a
tst.l (A2) ;check for eol
beq QuitSearch ;branch if so
tst.l 4(A2) ;test for skip_over
bmi.b .IncListA ;branch if so
moveq #0,D4 ;clr flag (print sourceline)
movea.l A2,A3 ;set list_b
.IncListB addq.l #8,A3 ;inc. list_b
move.l (A3),D1 ;check for eol
beq QuitSearch ;branch if so
tst.l 4(A3) ;test for skip_over
bmi.b .IncListB ;branch if so
;-----------------------------------------------
moveq #18,D2 ;loopcounter
movea.l (A2),A0 ;get filename_field entry (a)
movea.l D1,A1 ;get filename_field entry (b)
.Compare_1 move.b (A0)+,D0 ;compare filenames
move.b (A1)+,D1 ;char. by char.
or.b D5,D0 ;force lowercase
or.b D5,D1 ;for both
cmp.b D0,D1 ;compare chars.
dbne D2,.Compare_1 ;do loop as long as equal
;and counter is positive
tst.w D2 ;found same filenames ?
bpl.b .IncListA ;branch if not
;-----------------------------------------------
moveq #4,D2 ;loopcounter
lea 11(A0),A0 ;get size_field entry (a)
lea 11(A1),A1 ;get size_field entry (b)
.Compare_2 move.b (A0)+,D0 ;compare filesizes
move.b (A1)+,D1 ;char. by char.
or.b D5,D0 ;force lowercase
or.b D5,D1 ;for both
cmp.b D0,D1 ;compare chars.
dbne D2,.Compare_2 ;do loop as long as equal
;and counter is positive
tst.w D2 ;found equal filesize ?
bpl.b .IncListB ;branch if not
pea .IncListB(pc) ;set return_address
bra WriteEntries ;save entries
*****************************************************************************
cnop 0,4
*****************************************************************************
* search FILENAME, AGE, DESCRIPTION
Search_4 move.l D7,D1 ;set file
lea String4(pc),A0 ;get buffer
move.l A0,D2 ;set buffer
move.l #S4Size,D3 ;set length
jsr _LVOWrite(A6) ;use DOS to (write) bytes
movea.l EList(A5),A2 ;entrylist
subq.l #8,A2 ;simple avoids bra!
.IncListA addq.l #8,A2 ;inc. list_a
tst.l (A2) ;check for eol
beq QuitSearch ;branch if so
tst.l 4(A2) ;test for skip_over
bmi.b .IncListA ;branch if so
moveq #0,D4 ;clr flag (print sourceline)
movea.l A2,A3 ;set list_b
.IncListB addq.l #8,A3 ;inc. list_b
move.l (A3),D1 ;check for eol
beq QuitSearch ;branch if so
tst.l 4(A3) ;test for skip_over
bmi.b .IncListB ;branch if so
;-----------------------------------------------
moveq #18,D2 ;loopcounter
movea.l (A2),A0 ;get filename_field entry (a)
movea.l D1,A1 ;get filename_field entry (b)
.Compare_1 move.b (A0)+,D0 ;compare filenames
move.b (A1)+,D1 ;char. by char.
or.b D5,D0 ;force lowercase
or.b D5,D1 ;for both
cmp.b D0,D1 ;compare chars.
dbne D2,.Compare_1 ;do loop as long as equal
;and counter is positive
tst.w D2 ;found same filenames ?
bpl.b .IncListA ;branch if not
;-----------------------------------------------
moveq #2,D2 ;loopcounter
lea 16(A0),A0 ;get age_field entry (a)
lea 16(A1),A1 ;get age_field entry (b)
.Compare_3 move.b (A0)+,D0 ;compare filesizes
move.b (A1)+,D1 ;char. by char.
or.b D5,D0 ;force lowercase
or.b D5,D1 ;for both
cmp.b D0,D1 ;compare chars.
dbne D2,.Compare_3 ;do loop as long as equal
;and counter is positive
tst.w D2 ;found equal filesize ?
bpl.b .IncListB ;branch if not
;-----------------------------------------------
move.l 4(A2),D2 ;loopcounter
sub.l #39,D2
.Compare_4 move.b (A0)+,D0 ;compare file_descriptions
move.b (A1)+,D1 ;char. by char.
or.b D5,D0 ;force lowercase
or.b D5,D1 ;for both
cmp.b D0,D1 ;compare chars.
dbne D2,.Compare_4 ;do loop as long as equal
;and counter is positive
tst.w D2 ;found same description ?
bpl.b .IncListB ;branch if not
pea .IncListB(pc) ;set return_address
bra WriteEntries ;save entries
*****************************************************************************
cnop 0,4
*****************************************************************************
* search FILENAME, SIZE, AGE
Search_3 move.l D7,D1 ;set file
lea String3(pc),A0 ;get buffer
move.l A0,D2 ;set buffer
move.l #S3Size,D3 ;set length
jsr _LVOWrite(A6) ;use DOS to (write) bytes
movea.l EList(A5),A2 ;entrylist
subq.l #8,A2 ;simple avoids bra!
.IncListA addq.l #8,A2 ;inc. list_a
tst.l (A2) ;check for eol
beq QuitSearch ;branch if so
tst.l 4(A2) ;test for skip_over
bmi.b .IncListA ;branch if so
moveq #0,D4 ;clr flag (print sourceline)
movea.l A2,A3 ;set list_b
.IncListB addq.l #8,A3 ;inc. list_b
move.l (A3),D1 ;check for eol
beq QuitSearch ;branch if so
tst.l 4(A3) ;test for skip_over
bmi.b .IncListB ;branch if so
;-----------------------------------------------
moveq #18,D2 ;loopcounter
movea.l (A2),A0 ;get filename_field entry (a)
movea.l D1,A1 ;get filename_field entry (b)
.Compare_1 move.b (A0)+,D0 ;compare filenames
move.b (A1)+,D1 ;char. by char.
or.b D5,D0 ;force lowercase
or.b D5,D1 ;for both
cmp.b D0,D1 ;compare chars.
dbne D2,.Compare_1 ;do loop as long as equal
;and counter is positive
tst.w D2 ;found same filenames ?
bpl.b .IncListA ;branch if not
;-----------------------------------------------
moveq #4,D2 ;loopcounter
lea 11(A0),A0 ;get size_field entry (a)
lea 11(A1),A1 ;get size_field entry (b)
.Compare_2 move.b (A0)+,D0 ;compare filesizes
move.b (A1)+,D1 ;char. by char.
or.b D5,D0 ;force lowercase
or.b D5,D1 ;for both
cmp.b D0,D1 ;compare chars.
dbne D2,.Compare_2 ;do loop as long as equal
;and counter is positive
tst.w D2 ;found equal filesize ?
bpl.b .IncListB ;branch if not
;-----------------------------------------------
moveq #2,D2 ;loopcounter
.Compare_3 move.b (A0)+,D0 ;compare fileages
move.b (A1)+,D1 ;char. by char.
or.b D5,D0 ;force lowercase
or.b D5,D1 ;for both
cmp.b D0,D1 ;compare chars.
dbne D2,.Compare_3 ;do loop as long as equal
;and counter is positive
tst.w D2 ;found equal filesize ?
bpl.b .IncListB ;branch if not
pea .IncListB(pc) ;set return_address
bra WriteEntries ;save entries
*****************************************************************************
cnop 0,4
*****************************************************************************
* search FILENAME, SIZE, DESCRIPTION
Search_2 move.l D7,D1 ;set file
lea String2(pc),A0 ;get buffer
move.l A0,D2 ;set buffer
move.l #S2Size,D3 ;set length
jsr _LVOWrite(A6) ;use DOS to (write) bytes
movea.l EList(A5),A2 ;entrylist
subq.l #8,A2 ;simple avoids bra!
.IncListA addq.l #8,A2 ;inc. list_a
tst.l (A2) ;check for eol
beq QuitSearch ;branch if so
tst.l 4(A2) ;test for skip_over
bmi.b .IncListA ;branch if so
moveq #0,D4 ;clr flag (print sourceline)
movea.l A2,A3 ;set list_b
.IncListB addq.l #8,A3 ;inc. list_b
move.l (A3),D1 ;check for eol
beq QuitSearch ;branch if so
tst.l 4(A3) ;test for skip_over
bmi.b .IncListB ;branch if so
;-----------------------------------------------
moveq #18,D2 ;loopcounter
movea.l (A2),A0 ;get filename_field entry (a)
movea.l D1,A1 ;get filename_field entry (b)
.Compare_1 move.b (A0)+,D0 ;compare filenames
move.b (A1)+,D1 ;char. by char.
or.b D5,D0 ;force lowercase
or.b D5,D1 ;for both
cmp.b D0,D1 ;compare chars.
dbne D2,.Compare_1 ;do loop as long as equal
;and counter is positive
tst.w D2 ;found same filenames ?
bpl.b .IncListA ;branch if not
;-----------------------------------------------
moveq #4,D2 ;loopcounter
lea 11(A0),A0 ;get size_field entry (a)
lea 11(A1),A1 ;get size_field entry (b)
.Compare_2 move.b (A0)+,D0 ;compare filesizes
move.b (A1)+,D1 ;char. by char.
or.b D5,D0 ;force lowercase
or.b D5,D1 ;for both
cmp.b D0,D1 ;compare chars.
dbne D2,.Compare_2 ;do loop as long as equal
;and counter is positive
tst.w D2 ;found equal filesize ?
bpl.b .IncListB ;branch if not
;-----------------------------------------------
move.l 4(A2),D2 ;loopcounter
sub.l #39,D2
addq #3,A0 ;get description_field (a)
addq #3,A1 ;get description_field (b)
.Compare_4 move.b (A0)+,D0 ;compare file_descriptions
move.b (A1)+,D1 ;char. by char.
or.b D5,D0 ;force lowercase
or.b D5,D1 ;for both
cmp.b D0,D1 ;compare chars.
dbne D2,.Compare_4 ;do loop as long as equal
;and counter is positive
tst.w D2 ;found same description ?
bpl.b .IncListB ;branch if not
pea .IncListB(pc) ;set return_address
bra WriteEntries ;save entries
*****************************************************************************
cnop 0,4
*****************************************************************************
* search FILENAME, SIZE, AGE, DESCRIPTION
Search_1 move.l D7,D1 ;set file
lea String1(pc),A0 ;get buffer
move.l A0,D2 ;set buffer
move.l #S1Size,D3 ;set length
jsr _LVOWrite(A6) ;use DOS to (write) bytes
movea.l EList(A5),A2 ;entrylist
subq.l #8,A2 ;simple avoids bra!
.IncListA addq.l #8,A2 ;inc. list_a
tst.l (A2) ;check for eol
beq QuitSearch ;branch if so
tst.l 4(A2) ;test for skip_over
bmi.b .IncListA ;branch if so
moveq #0,D4 ;clr flag (print sourceline)
movea.l A2,A3 ;set list_b
.IncListB addq.l #8,A3 ;inc. list_b
move.l (A3),D1 ;check for eol
beq QuitSearch ;branch if so
tst.l 4(A3) ;test for skip_over
bmi.b .IncListB ;branch if so
;-----------------------------------------------
moveq #18,D2 ;loopcounter
movea.l (A2),A0 ;get filename_field entry (a)
movea.l D1,A1 ;get filename_field entry (b)
.Compare_1 move.b (A0)+,D0 ;compare filenames
move.b (A1)+,D1 ;char. by char.
or.b D5,D0 ;force lowercase
or.b D5,D1 ;for both
cmp.b D0,D1 ;compare chars.
dbne D2,.Compare_1 ;do loop as long as equal
;and counter is positive
tst.w D2 ;found same filenames ?
bpl.b .IncListA ;branch if not
;-----------------------------------------------
moveq #4,D2 ;loopcounter
lea 11(A0),A0 ;get size_field entry (a)
lea 11(A1),A1 ;get size_field entry (b)
.Compare_2 move.b (A0)+,D0 ;compare filesizes
move.b (A1)+,D1 ;char. by char.
or.b D5,D0 ;force lowercase
or.b D5,D1 ;for both
cmp.b D0,D1 ;compare chars.
dbne D2,.Compare_2 ;do loop as long as equal
;and counter is positive
tst.w D2 ;found equal filesize ?
bpl.b .IncListB ;branch if not
;-----------------------------------------------
moveq #2,D2 ;loopcounter
.Compare_3 move.b (A0)+,D0 ;compare fileages
move.b (A1)+,D1 ;char. by char.
or.b D5,D0 ;force lowercase
or.b D5,D1 ;for both
cmp.b D0,D1 ;compare chars.
dbne D2,.Compare_3 ;do loop as long as equal
;and counter is positive
tst.w D2 ;found equal filesize ?
bpl.b .IncListB ;branch if not
;-----------------------------------------------
move.l 4(A2),D2 ;loopcounter
sub.l #39,D2
.Compare_4 move.b (A0)+,D0 ;compare file_descriptions
move.b (A1)+,D1 ;char. by char.
or.b D5,D0 ;force lowercase
or.b D5,D1 ;for both
cmp.b D0,D1 ;compare chars.
dbne D2,.Compare_4 ;do loop as long as equal
;and counter is positive
tst.w D2 ;found same description ?
bpl.b .IncListB ;branch if not
pea .IncListB(pc) ;set return_address
bra.b WriteEntries ;save entries
*****************************************************************************
cnop 0,4
*****************************************************************************
* search FILENAME, PATH
Search_0 move.l D7,D1 ;set file
lea String0(pc),A0 ;get buffer
move.l A0,D2 ;set buffer
move.l #S0Size,D3 ;set length
jsr _LVOWrite(A6) ;use DOS to (write) bytes
movea.l EList(A5),A2 ;entrylist
subq.l #8,A2 ;simple avoids bra!
.IncListA addq.l #8,A2 ;inc. list_a
tst.l (A2) ;check for eol
beq.b QuitSearch ;branch if so
tst.l 4(A2) ;test for skip_over
bmi.b .IncListA ;branch if so
moveq #0,D4 ;clr flag (print sourceline)
movea.l A2,A3 ;set list_b
.IncListB addq.l #8,A3 ;inc. list_b
move.l (A3),D1 ;check for eol
beq.b QuitSearch ;branch if so
tst.l 4(A3) ;test for skip_over
bmi.b .IncListB ;branch if so
;-----------------------------------------------
moveq #29,D2 ;loopcounter
movea.l (A2),A0 ;get filename_field entry (a)
movea.l D1,A1 ;get filename_field entry (b)
.Compare_1 move.b (A0)+,D0 ;compare filenames
move.b (A1)+,D1 ;char. by char.
or.b D5,D0 ;force lowercase
or.b D5,D1 ;for both
cmp.b D0,D1 ;compare chars.
dbne D2,.Compare_1 ;do loop as long as equal
;and counter is positive
tst.w D2 ;found same filenames ?
bpl.b .IncListA ;branch if not
pea .IncListB(pc) ;set return_address
*****************************************************************************
WriteEntries tst.b D4 ;write entry (a) ?
bne.b .WriteEntry_b ;no, entry (b) only!
moveq #1,D4 ;flag, entry (a) written!
.WriteEntry_a move.l D7,D1 ;set file
move.l (A2),D2 ;set buffer
move.l 4(A2),D3 ;set length
jsr _LVOWrite(A6) ;use DOS to (write) bytes
add.l D0,Count(A5) ;counter (written bytes)
or.l D6,4(A2) ;set flag (skip_over)
.WriteEntry_b move.l D7,D1 ;set file
move.l (A3),D2 ;set buffer
move.l 4(A3),D3 ;set length
jsr _LVOWrite(A6) ;use DOS to (write) bytes
add.l D0,Count(A5) ;counter (written bytes)
or.l D6,4(A3) ;set flag (skip_over)
QuitSearch rts ;quit search (equal)
*****************************************************************************
String0 dc.b $A," ** entries - including same FILENAME; PATH",$A,$A
S0Size equ *-String0
String1 dc.b $A," ** entries - including same FILENAME; SIZE; AGE; DESCRIPTION",$A,$A
S1Size equ *-String1
String2 dc.b $A," ** entries - including same FILENAME; SIZE; DESCRIPTION",$A,$A
S2Size equ *-String2
String3 dc.b $A," ** entries - including same FILENAME; SIZE; AGE",$A,$A
S3Size equ *-String3
String4 dc.b $A," ** entries - including same FILENAME; AGE; DESCRIPTION",$A,$A
S4Size equ *-String4
String5 dc.b $A," ** entries - including same FILENAME; SIZE",$A,$A
S5Size equ *-String5
String6 dc.b $A," ** entries - including same FILENAME; AGE",$A,$A
S6Size equ *-String6
String7 dc.b $A," ** entries - including same FILENAME; DESCRIPTION",$A,$A
S7Size equ *-String7
String8 dc.b $A," ** entries - including same FILENAME",$A,$A
S8Size equ *-String8
*****************************************************************************
cnop 0,4
*****************************************************************************
SkipHeader movea.l MemoryA(A5),A0 ;get base of file
tst.l SkipHead(A5) ;skip some lines?
beq.b .quit ;no, quit
movea.l SkipHead(A5),A1 ;get skiphead value
move.l (A1),D0 ;set count
moveq #116,D1 ;preset errorcode
moveq #10,D2 ;linefeed
.getlines cmp.b (A0)+,D2 ;search linefeed
bne.b .getlines
tst.b (A0) ;check for eof
beq Error1 ;branch if so!
subq.l #1,D0 ;dec. counter
bne.b .getlines ;do until zero
.quit move.l A0,MemoryB(A5) ;set new base of file
rts ;go back
*****************************************************************************
cnop 0,4
*****************************************************************************
OpenOFile move.l OutputFile(A5),D1 ;get filename
move.l #MODE_NEWFILE,D2 ;open new file!!
movea.l DOSBase(A5),A6 ;set dos_base
jsr _LVOOpen(A6) ;use dos to open file
move.l D0,OHandle(A5) ;save handle
beq Error2 ;print error when fail
rts ;go back
*****************************************************************************
cnop 0,4
*****************************************************************************
OpenSFile move.l SortedFile(A5),D1 ;get filename
beq.b .quit ;branch if not given
move.l #MODE_NEWFILE,D2 ;open new file
movea.l DOSBase(A5),A6 ;set dos_base
jsr _LVOOpen(A6) ;use dos to open file
move.l D0,SHandle(A5) ;save handle
beq Error2 ;branch if fail
.quit rts ;go back
*****************************************************************************
cnop 0,4
*****************************************************************************
CloseOFile move.l OHandle(A5),D1 ;set filehandle
beq.b .quit ;branch if not set!
movea.l DOSBase(A5),A6 ;set DOS to call a function
jsr _LVOClose(A6) ;use DOS to (close) file
moveq #0,D0 ;clear filehandle
move.l D0,OHandle(A5)
tst.l Count(A5) ;some bytes written ?
bne.b .quit ;branch if so
move.l OutputFile(A5),D1 ;set filename
jsr _LVODeleteFile(A6) ;use dos to (delete) file
.quit rts ;go back
*****************************************************************************
cnop 0,4
*****************************************************************************
CloseSFile move.l SHandle(A5),D1 ;set filehandle
beq.b .quit ;branch if not given
movea.l DOSBase(A5),A6 ;set DOS to call a function
jsr _LVOClose(A6) ;use DOS to (close) file
moveq #0,D0 ;clear filehandle
move.l D0,SHandle(A5)
tst.l SCount(A5) ;some bytes written ?
bne.b .quit ;branch if so
move.l SortedFile(A5),D1 ;set filename
jsr _LVODeleteFile(A6) ;use dos to (delete) file
.quit rts ;go back
*****************************************************************************
cnop 0,4
*****************************************************************************
GetIFile move.l IndexFile(A5),D1 ;get filename
move.l #MODE_OLDFILE,D2 ;file exists!
movea.l DOSBase(A5),A6 ;set dos_base
jsr _LVOOpen(A6) ;use dos to open file
move.l D0,IHandle(A5) ;save filehandle
beq Error2 ;branch if not found
;-----------------------------------------------
move.l IHandle(A5),D1 ;set filehandle
lea FIBlock(A5),A3 ;get buffer for FIB
move.l A3,D2 ;set FileInfoBlock
jsr _LVOExamineFH(A6) ;use DOS to (examinefh)
tst.l D0 ;test for success
beq Error2 ;branch if not (close file)
;-----------------------------------------------
move.l fib_Size(A3),D0 ;set filesize
beq Error2 ;empty file?...
addq.l #2,D0 ;need one linefeed +
;null terminator at eof
addq.l #3,D0 ;get long aligned
and.b #-4,D0 ;get long aligned
addq.l #4,D0 ;add room for security ID
moveq #0,D1 ;no options
movea.l 4.w,A6 ;set EXEC to call a function
jsr _LVOAllocMem(A6) ;use EXEC to (allocmem)
move.l D0,MemoryA(A5) ;save memorybase
beq Error2 ;branch if fail (close file)
;----------------------------------------------------------------------------
move.l IHandle(A5),D1 ;set filehandle (read)
movea.l MemoryA(A5),A2 ;get membase (endmark)
move.l A2,D2 ;set membase (read)
move.l fib_Size(A3),D3 ;set filesize (read)
;-----------------------------------------------
move.l D3,D0 ;get filesize
addq.l #2,D0 ;need one linefeed +
;null terminator at eof
addq.l #3,D0 ;get long aligned
and.b #-4,D0 ;get long aligned
move.l #"EOF!",0(A2,D0.l) ;set security ID
;-----------------------------------------------
movea.l DOSBase(A5),A6 ;set DOS to call a function
jsr _LVORead(A6) ;use DOS to (read) bytes
cmp.l D0,D3 ;test for success
bne Error2 ;branch if fail (free mem)
;----------------------------------------------------------------------------
moveq #10,D0 ;get linefeed
lea -1(A2,D3.l),A0 ;jump to eof
cmp.b (A0)+,D0 ;check for linefeed
beq.b .skip ;branch if set
move.b D0,(A0)+ ;add a linefeed at eof
.skip clr.b (A0) ;set terminator
************************************************
CloseIFile move.l IHandle(A5),D1 ;set filehandle
beq.b .skip
movea.l DOSBase(A5),A6 ;set DOS to call a function
jsr _LVOClose(A6) ;use DOS to (close) file
moveq #0,D0 ;clear filehandle
move.l D0,IHandle(A5)
.skip rts ;go back
*****************************************************************************
cnop 0,4
*****************************************************************************
FreeMem move.l MemoryA(A5),D1 ;get file memory
beq.b .skip ;branch if not set
movea.l D1,A1 ;set memory base
lea FIBlock(A5),A0 ;get fileinfoblock
move.l fib_Size(A0),D0 ;set filesize
addq.l #2,D0 ;need one linefeed +
;null terminator at eof
addq.l #3,D0 ;get long aligned
and.b #-4,D0 ;get long aligned
addq.l #4,D0 ;add room for security ID
movea.l 4.w,A6 ;set EXEC to call a function
jsr _LVOFreeMem(A6) ;use EXEC to (freemem)
moveq #0,D0 ;clear pointer
move.l D0,MemoryA(A5)
.skip rts ;go back
*****************************************************************************
cnop 0,4
*****************************************************************************
FreeEList move.l EList(A5),D1 ;get elist memory
beq.b .skip ;branch if not set
movea.l D1,A1 ;set memory base
move.l ELSize(A5),D0 ;set size
movea.l 4.w,A6 ;set EXEC to call a function
jsr _LVOFreeMem(A6) ;use EXEC to (freemem)
moveq #0,D0 ;clear pointer
move.l D0,EList(A5)
.skip rts ;go back
*****************************************************************************
cnop 0,4
*****************************************************************************
ReadArgs lea Template(pc),A1 ;get template
lea ArgArray(A5),A2 ;get arg_array
move.l A1,D1 ;set arg_template
move.l A2,D2 ;set array
moveq #0,D3 ;set args (unused)
movea.l DOSBase(A5),A6 ;set dos_base
jsr _LVOReadArgs(A6) ;use dos to readargs
move.l D0,RDArgs(A5) ;save returncode
beq.b Error2
rts ;else, go back
*****************************************************************************
Template dc.b "INDEX/A,OUTPUT/A,WS=WRITESORTED/K,SKIP/N",0
Header dc.b "ERROR",0
*****************************************************************************
cnop 0,4
*****************************************************************************
CheckArgs moveq. #116,D1 ;errorcode "wrong args..."
tst.l IndexFile(A5) ;the indexfile (required)
beq.b Error1
tst.l OutputFile(A5) ;the outputfile (required)
beq.b Error1 ;branch if nothing set
rts
*****************************************************************************
cnop 0,4
************************************************ free argument buffer *******
FreeArgs move.l RDArgs(A5),D1 ;get arg_structure
beq.b .skip ;branch if not set
move.l DOSBase(A5),A6 ;set dos_base
jsr _LVOFreeArgs(A6) ;use dos to freeargs
moveq #0,D0 ;clear pointer
move.l D0,RDArgs(A5)
.skip rts ;go back
*****************************************************************************
cnop 0,4
*****************************************************************************
Error3 move.w #304,D1 ;set errorcode "***Break"
ext.l D1 ;clear highword
bra.b Error1
Error2 moveq #0,D1 ;get errorcode by dos
Error1 addq #4,SP ;clear return_address
move.l D1,RCode2(A5) ;set errorcode
pea Quit(pc) ;set return_address
Error0 move.l RCode2(A5),D1 ;get errorcode
bne.b .skip ;branch if known!
movea.l DOSBase(A5),A6 ;set dos to call a function
jsr _LVOIoErr(A6) ;use dos to get (ioerr)
move.l D0,D1 ;get errorcode
move.l D1,RCode2(A5) ;set errorcode
.skip movea.l DOSBase(A5),A6 ;set dos_base
jsr _LVOSetIoErr(A6) ;use dos to set pr_result2
move.l RCode2(A5),D1 ;get errorcode
moveq #0,D2 ;prepare dos printfault
cmp.w #304,D1 ;check for break by user
beq.b .PrintFault ;branch if so
lea Header(pc),A2 ;get head_text 'ERROR:'
move.l A2,D2 ;set header
.PrintFault jsr _LVOPrintFault(A6) ;use dos to printfault
moveq #5,D0 ;set returncode rc=warn
move.l D0,RCode1(A5) ;save
rts ;go back
*****************************************************************************
if BSS_Section
SECTION ChkIndex_bss,BSS
elseif
cnop 0,4
endc
*****************************************************************************
DataBase ds.b BSS_Size
end of source **************************************************************